package com.itheima.user.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.user.pojo.ItemsFootprint;
import com.itheima.user.service.ItemsFootprintService;
import com.itheima.util.Result;
import com.itheima.util.StatusCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/****
 * @Author:itheima
 * @Description:
 *****/
@Api(value = "ItemsFootprintController")
@RestController
@RequestMapping("/itemsFootprint")
@CrossOrigin
public class ItemsFootprintController {

    @Autowired
    private ItemsFootprintService itemsFootprintService;

    /***
     * ItemsFootprint分页条件搜索实现
     * @param itemsFootprint
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "ItemsFootprint条件分页查询",notes = "分页条件查询ItemsFootprint方法详情",tags = {"ItemsFootprintController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "ItemsFootprint对象",value = "传入JSON数据",required = false) ItemsFootprint itemsFootprint, @PathVariable  int page, @PathVariable  int size){
        //调用ItemsFootprintService实现分页条件查询ItemsFootprint
        PageInfo<ItemsFootprint> pageInfo = itemsFootprintService.findPage(itemsFootprint, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * ItemsFootprint分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "ItemsFootprint分页查询",notes = "分页查询ItemsFootprint方法详情",tags = {"ItemsFootprintController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用ItemsFootprintService实现分页查询ItemsFootprint
        PageInfo<ItemsFootprint> pageInfo = itemsFootprintService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param itemsFootprint
     * @return
     */
    @ApiOperation(value = "ItemsFootprint条件查询",notes = "条件查询ItemsFootprint方法详情",tags = {"ItemsFootprintController"})
    @PostMapping(value = "/search" )
    public Result<List<ItemsFootprint>> findList(@RequestBody(required = false) @ApiParam(name = "ItemsFootprint对象",value = "传入JSON数据",required = false) ItemsFootprint itemsFootprint){
        //调用ItemsFootprintService实现条件查询ItemsFootprint
        List<ItemsFootprint> list = itemsFootprintService.findList(itemsFootprint);
        return new Result<List<ItemsFootprint>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "ItemsFootprint根据ID删除",notes = "根据ID删除ItemsFootprint方法详情",tags = {"ItemsFootprintController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "String")
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        //调用ItemsFootprintService实现根据主键删除
        itemsFootprintService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改ItemsFootprint数据
     * @param itemsFootprint
     * @param id
     * @return
     */
    @ApiOperation(value = "ItemsFootprint根据ID修改",notes = "根据ID修改ItemsFootprint方法详情",tags = {"ItemsFootprintController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "String")
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "ItemsFootprint对象",value = "传入JSON数据",required = false) ItemsFootprint itemsFootprint,@PathVariable String id){
        //设置主键值
        itemsFootprint.setId(id);
        //调用ItemsFootprintService实现修改ItemsFootprint
        itemsFootprintService.update(itemsFootprint);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增ItemsFootprint数据
     * @param itemsFootprint
     * @return
     */
    @ApiOperation(value = "ItemsFootprint添加",notes = "添加ItemsFootprint方法详情",tags = {"ItemsFootprintController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "ItemsFootprint对象",value = "传入JSON数据",required = true) ItemsFootprint itemsFootprint){
        //调用ItemsFootprintService实现添加ItemsFootprint
        itemsFootprintService.add(itemsFootprint);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询ItemsFootprint数据
     * @param id
     * @return
     */
    @ApiOperation(value = "ItemsFootprint根据ID查询",notes = "根据ID查询ItemsFootprint方法详情",tags = {"ItemsFootprintController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "String")
    @GetMapping("/{id}")
    public Result<ItemsFootprint> findById(@PathVariable String id){
        //调用ItemsFootprintService实现根据主键查询ItemsFootprint
        ItemsFootprint itemsFootprint = itemsFootprintService.findById(id);
        return new Result<ItemsFootprint>(true,StatusCode.OK,"查询成功",itemsFootprint);
    }

    /***
     * 查询ItemsFootprint全部数据
     * @return
     */
    @ApiOperation(value = "查询所有ItemsFootprint",notes = "查询所ItemsFootprint有方法详情",tags = {"ItemsFootprintController"})
    @GetMapping
    public Result<List<ItemsFootprint>> findAll(){
        //调用ItemsFootprintService实现查询所有ItemsFootprint
        List<ItemsFootprint> list = itemsFootprintService.findAll();
        return new Result<List<ItemsFootprint>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
